package com.ecreditpal.audio.netty.handler;

import com.ecreditpal.audio.model.AudioModel;
import com.ecreditpal.audio.netty.model.PersonModel;
import com.google.protobuf.MessageLite;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import lombok.extern.slf4j.Slf4j;

/**
 * @author lifeng
 * @version 1.0 on 2018/7/4.
 */
@Slf4j
public class SubReqClientHandler extends ChannelInboundHandlerAdapter {

    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        ctx.fireChannelActive();
    }

    /**
     *此方法会在接收到服务器数据后调用
     * */
    public void channelRead(ChannelHandlerContext ctx, Object msg) {
        if (!(msg instanceof MessageLite)){
            ctx.fireChannelRead(msg);
            return;
        }

        AudioModel.Text req = (AudioModel.Text) msg;
        log.info("id:{},message:{},start:{},end:{},isLast:{}",
                req.getCaseid(),
                req.getContent(),
                req.getBeginTime(),
                req.getEndTime(),
                req.getIsLast());
    }


    private PersonModel.Person subReq(int i) {
        PersonModel.Person.Builder builder = PersonModel.Person.newBuilder();

        builder.setId(i);
        return builder.build();
    }


}
